<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World H5 postMessage</title>
</head>
<script type="text/javascript">
	var win;
	window.onload = function() {
		//弹出框
		var url = 'http://www.d.com:8080/proj4/index.jsp';
		win = window.open(url, '_blank', 'width=600,height=400');
	}

	//接收postMessage传递过来的数据
	if (window.addEventListener) {
		window.addEventListener('message', receiveMessage, false);
	} else {
		window.attachEvent('message', receiveMessage);
	}

	function receiveMessage(e) {
		var div = document.getElementById('div');
		div.innerHTML = "origin-->" + e.origin + "-----------------  data-->"
				+ e.data;
	}

	//----------------------------向子页面传递数据---------------------------------------
	function postSubMsg() {
		var domain = 'http://www.d.com:8080';
		var str = document.getElementById('sub').value;
		/**
		 *	postMessage:前面的window是要接收message的window对象
		 *	domain:接收message信息的窗口的  协议：//域名:端口
		 **/
		win.postMessage(str, domain);
	}
</script>
<body>
	传递给子页面的内容:
	<input type='text' id='sub' value=''>
	<input type='button' value='向子页面传输数据' onclick='postSubMsg();' />
	获取弹出框传递的内容：
	<br />
	<div id='div'></div>


</body>
</html>